//
//  CategoryView.m
//  随手记
//
//  Created by Medalands on 15/11/5.
//  Copyright (c) 2015年 Medalands. All rights reserved.
//

#import "CategoryView.h"

@interface CategoryView ()
@property (nonatomic , strong) NSArray *tmpArray;
@property (nonatomic , strong) NSMutableArray *buttonArray;
@property (nonatomic , strong) NSArray *imageArray;
@end

@implementation CategoryView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        [self setUpDefult];
        [self setUpDataSources];
        [self setUpButton];
        [self.layer setCornerRadius:5.0f];
    }
    return self;
}

- (void) setUpDefult{
    
    UILabel *label = [[UILabel alloc] initWithFrame:KRECT(0, 0, self.frame.size.width, 20)];
    
    [label setText:@"请选择分类项目"];
    
    [label setTextAlignment:(NSTextAlignmentCenter)];
    
    [label setFont:[UIFont boldSystemFontOfSize:14.0f]];
    
    [label setBackgroundColor:[UIColor clearColor]];
    
    [self addSubview:label];
    
}

- (void) setUpDataSources{
    
    self.tmpArray = @[@"餐饮",@"交通",@"住宿",@"门票",@"活动",@"物业",@"通讯",@"购物",@"其他"];

    self.buttonArray = [NSMutableArray array];
}

- (void) setUpButton{
    
    for (NSInteger i = 0;  i < 9; i ++) {
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        
        [button setFrame:KRECT(5, 22+(self.frame.size.height - 22 - 9 * 1)/9*i,self.frame.size.width - 10, (self.frame.size.height - 49)/9)];
        
        [button setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];
        
        [button setBackgroundColor:RGBA(242, 242, 242)];
        
        [button.layer setCornerRadius:5];
        
        [button setTitle:[NSString stringWithFormat:@"  %@",self.tmpArray[i]] forState:(UIControlStateNormal)];
        
        [button addTarget:self action:@selector(buttonDidPress:) forControlEvents:(UIControlEventTouchUpInside)];
        
        [self.buttonArray addObject:button];
        
        [self addSubview:button];
    }
    
}

- (void) buttonDidPress:(UIButton *)sender{
    
    NSLog(@"%@",sender.titleLabel.text);
    
    
    
    if (self.sendTitleTo) {
        self.sendTitleTo(sender.titleLabel.text);
    }
}


@end
